import os
import sys
import re


class Init_app:
    def setGit(self):
        if (len(sys.argv) == 2):
            self.workName = sys.argv[1]
            os.system("git remote add origin " + sys.argv[1])
            os.system("git branch dev")
            os.system("git push -u origin dev:dev")
            os.system("git checkout dev")
        else:
            print("参数错误！")

    def gitInit(self):
        os.system("rm -rf .git")
        os.system("git init")
        os.system("git add -A")
        os.system("git commit -m 'init'")

    def changeDir(self):
        str = self.workName
        p = re.compile(r'([^/]*[.]{1}git)')
        nStr = p.findall(str)[0]
        eNum = len(nStr) - 4
        nStr = nStr[0:eNum]

        oldPath = os.path.abspath('..')
        oldDir = os.getcwd()
        newDir = oldPath + "/" + nStr
        os.rename(oldDir, newDir)
        print("cd " + newDir)

    def __init__(self):
        # os.system("git branch dev")
        # os.system("git checkout dev")

        self.gitInit()
        self.setGit()
        self.changeDir()


app = Init_app()
